﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class AdminPages_AddDVD : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        TableCell MovieID = GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0];

        if(e.CommandName.Equals("addDVD"))
        {
            DVDTableAdapters.DVDStockTableAdapter ta = new DVDTableAdapters.DVDStockTableAdapter();
            ta.Insert(Convert.ToInt32(MovieID.Text),true);
        }
        else if(e.CommandName.Equals("removeDVD"))
        {
            DVDTableAdapters.DVDStockTableAdapter ta = new DVDTableAdapters.DVDStockTableAdapter();
            int StockID = 0;
            StockID = (int)ta.ScalarQuery(Convert.ToInt32(MovieID.Text));

            if (StockID!=0)
            {
                DVDTableAdapters.DVDHistory1TableAdapter ta1 = new DVDTableAdapters.DVDHistory1TableAdapter();
                //remove from dvd history
                ta1.UpdateDVDremoveStock(StockID);
                //remove from stock
                ta.DeleteDVD(StockID);
            }

        }
        else if (e.CommandName.Equals("setnull"))
            {
            DVDTableAdapters.DVDHistory1TableAdapter ta1 = new DVDTableAdapters.DVDHistory1TableAdapter();
            DVDTableAdapters.DVDStockTableAdapter ta = new DVDTableAdapters.DVDStockTableAdapter();

            //Remove from History
            ta1.RemoveAllDVDs(Convert.ToInt32(MovieID.Text));
            //remove from Stock
            ta.DeleteAllDVDFromMovie(Convert.ToInt32(MovieID.Text));

            }
        Response.Redirect(Request.RawUrl);
    }
    protected void btn_AddNewDvd_Click(object sender, EventArgs e)
    {
        DVDTableAdapters.DVDStockTableAdapter ta = new DVDTableAdapters.DVDStockTableAdapter();
        ta.InsertDVDStock(Convert.ToInt32(ddl_NewMovie.SelectedValue), true);
        Response.Redirect(Request.RawUrl);
    }
}
